import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout'

// 按需导入  懒加载
// const Layout = () => import('@/views/Layout')
// const Goods = () => import('@/views/goods/index')

// 路由规则
const routes = [
  // 一级路由布局容器
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        component: () => import('@/views/home/index.vue')
      },
      {
        path: '/category/:id',
        component: () => import('@/views/category/index.vue')
      },
      {
        path: '/category/sub/:id',
        component: () => import('@/views/category/sub.vue')
      },
      {
        path: '/product/:id',
        component: () => import('@/views/goods/index')
      },
      {
        path: '/cart',
        component: () => import('@/views/cart/index')
      },
    ]
  }, {
    path: '/login',
    component: () => import('@/views/login/index')
  }, {
    path: '/login/callback',
    component: () => import('@/views/login/callback')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior() {
    return { left: 0, top: 0 }
  }
})

export default router
